package com.lx.idgenerator.autoconfigure.redis;

import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wcy
 */
public class ClusterRedisConfiguration extends RedisClusterConfiguration {


    public ClusterRedisConfiguration(String clusterNodes) {
        super(new MapPropertySource("RedisClusterConfiguration", asMap(clusterNodes)));
    }

  public ClusterRedisConfiguration(List<String> clusterNodes) {
    super(clusterNodes);
  }

    private static Map<String, Object> asMap(String clusterNodes) {
        Assert.notNull(clusterNodes, "ClusterHostAndPorts must not be null!");
        Map<String, Object> map = new HashMap();
        map.put("spring.redis.cluster.nodes", clusterNodes);
        return map;
    }
}
